home *** CD-ROM | disk | FTP | other *** search
- /* File: Menus.c */
-
- #include "AESimple.h"
-
-
- void SetItemEnable (MenuHandle theMenu, short theItem, Boolean enabled)
- {
- if (enabled)
- EnableItem(theMenu, theItem);
- else
- DisableItem(theMenu, theItem);
- } /* SetItemEnable */
-
-
- void EnableFileCommands (Boolean userWindow)
- {
- MenuHandle fileMenu = GetMHandle(kFileMenu);
- WindowPtr inFront = FrontWindow();
- wiHand info = 0L;
- Boolean hasPicture = FALSE;
-
- if (userWindow) {
- info = (wiHand)GetWRefCon(inFront);
- hasPicture = ((info != NIL) && ((*info)->thePicture != NIL));
- }
- SetItemEnable(fileMenu, cNew, !((inFront != NIL) && (((WindowPeek)inFront)->windowKind == dialogKind)));
- SetItemEnable(fileMenu, cClose, (inFront != NIL) && (((WindowPeek)inFront)->goAwayFlag));
- SetItemEnable(fileMenu, cPageSetup, hasPicture);
- SetItemEnable(fileMenu, cPrint, hasPicture);
- } /* EnableFileCommands */
-
-
- void AdjustMenus()
- {
- enum {
- kNoWindows = 1,
- kUsingDA,
- kUsingDocWindow,
- kUsingSpecialWindow
- };
-
- WindowPtr inFront = FrontWindow();
- Boolean isAUserWindow, isDeskAcc;
- short newMenuState;
-
- if (inFront == NIL) {
- isAUserWindow = FALSE;
- DisableItem(GetMHandle(kEditMenu), 0);
- EnableFileCommands(FALSE);
- newMenuState = kNoWindows;
- } else {
- if (isAUserWindow = isUserWindow(inFront)) {
- EnableFileCommands(TRUE);
- DisableItem(GetMHandle(kEditMenu), 0);
- newMenuState = kUsingDocWindow;
- }
- else if (isDeskAcc = ((WindowPeek)inFront)->windowKind < 0) {
- EnableFileCommands(FALSE);
- EnableItem(GetMHandle(kEditMenu), 0);
- newMenuState = kUsingDA;
- } else {
- /* We have a window up front, but it's not a desk accessory or user window */
- EnableFileCommands(FALSE);
- newMenuState = kUsingSpecialWindow;
- }
- }
-
- if (newMenuState != gMenuState) {
- DrawMenuBar();
- gMenuState = newMenuState;
- }
- } /* AdjustMenus */
-
-
-
- void DoAppleCmds (short theItem)
- {
- Str255 name; /* string for DA name */
-
- switch (theItem) {
-
- case cAbout:
- Alert(kAboutDialog, NIL);
- break;
-
- default:
- GetItem(GetMHandle(kAppleMenu), theItem, (StringPtr)&name);
- OpenDeskAcc((StringPtr)&name);
- }
- }
-
-
- void DoFileCmds (short theItem)
- {
- long result = 0;
- FSSpec theFile;
-
- switch (theItem) {
-
- case cNew:
- NewDisplayWindow();
- break;
-
- case cOpen:
- if (select_file(&theFile)) {
- NewDisplayWindow();
- open_selected_file(&theFile, FrontWindow());
- }
- break;
-
- case cClose:
- CloseAWindow(FrontWindow());
- break;
-
- case cPageSetup:
- if (isUserWindow(FrontWindow()))
- ShowSetupDialog(FrontWindow());
- break;
-
- case cPrint:
- if (isUserWindow(FrontWindow()))
- if (ShowJobDialog(FrontWindow()))
- PrintWindow(FrontWindow());
- break;
-
- case cQuit:
- gDone = TRUE;
- }
- } /* DoFileCmds */
-
-
- void DoDemoCmds (short theItem)
- {
- switch (theItem) {
- }
- } /* DoDemoCmds */
-
-
-
-
- void Dispatch (long menuResult)
- {
- short theMenu = (menuResult >> 16); /* menu selected */
- short theItem = (menuResult & 0x0000FFFF); /* item selected */
-
- switch (theMenu) {
-
- case kAppleMenu:
- DoAppleCmds(theItem);
- break;
-
- case kFileMenu:
- DoFileCmds(theItem);
- break;
-
- case kEditMenu:
- SystemEdit(theItem - 1);
- break;
-
- case kDemoMenu:
- DoDemoCmds(theItem);
- break;
-
- }
- HiliteMenu(0); /* un-hilite selected menu */
- }
-
-